package com.easepal7506a.project.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by FHB on 2018/4/18.
 */
public class CloseAdvance {

    private static CloseAdvance mInst = null;
    private static Object mLock = new Object();

    private List<onTimeFinish> mOnCloseListerner;

    private CloseAdvance(){
        mOnCloseListerner = new ArrayList<onTimeFinish>();
    }

    public static CloseAdvance getInst(){
        if(mInst == null){
            synchronized(mLock){
                if(mInst == null){
                    mInst = new CloseAdvance();
                }
            }
        }
        return mInst;
    }

    public void  registerObserver(onTimeFinish action){
        if(!mOnCloseListerner.contains(action)){
            mOnCloseListerner.add(action);
        }
    }

    public void removeObserver(onTimeFinish action){
        mOnCloseListerner.remove(action);
    }


    public void noticeonClose(){
        for (int i = 0; i < mOnCloseListerner.size(); i++) {
            try {
                mOnCloseListerner.get(i).onTimeFinish();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public interface onTimeFinish {
        void onTimeFinish();


    }


}
